package com.gjl.app.oauth.params;

import com.gjl.app.common.Encoder;

public class KeyValuePair implements Comparable<KeyValuePair>{
	
	private static String KEY_VALUE_SEPARATOR = "%3D";
	
	private String key;
	
	private String value;
	
	public KeyValuePair(String key, String value) {
		this.key = key;
		this.value = value;
	}

	public String getKey() {
		return key;
	}

	public void setKey(String key) {
		this.key = key;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	@Override
	public int compareTo(KeyValuePair kvp) {
		if (kvp == null) {
			return 1;
		}
		int keyCompare = key.compareTo(kvp.key);
		if (keyCompare != 0) {
			return keyCompare;
		} else {
			return value.compareTo(kvp.value);
		}
	}
	
	@Override
	public String toString(){
		return Encoder.urlEncode(key)+ KEY_VALUE_SEPARATOR + Encoder.urlEncode(value);
	}

}
